/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import stendcontrol.StendLogger;

/**
 *
 * @author minaev
 */
public abstract class Timing implements Runnable {

    private int delay;
    private boolean runing = false;
    private Thread trd;

    public Timing(int delay) {
        super();
        this.delay = delay;
    }

    public void startTiming() {
        runing = true;
        trd = new Thread(this);
        trd.start();
    }
    
    public void stopTiming(){
        runing = false;
    }

    @Override
    public void run() {
        while (runing) {
            action();
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ex) {
                StendLogger.log(StendLogger.MSG_ERROR, "Error sleep in Timing: "
                        + ex.getMessage());
            }
        }
    }

    public abstract void action();
}
